<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*,
com.brother.model.*,com.brother.service.*"   pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ include file="../international.jsp" %> 
<%
String trackerId = request.getParameter("trackerId");
String action = request.getParameter("action");
String alarmId = request.getParameter("alarmId");

TrackerService tks = new TrackerService();

Tracker tracker = tks.getTrackerByFieldName("trackerId", trackerId);

AlarmService als = new AlarmService();

if("del".equals(action) && alarmId != null){
	als.deleteAlarm(alarmId);
}

Alarm alarm = new Alarm();
alarm.setTrackerId(tracker.getTrackerid());
alarm.setAlarmType(AlarmType.Geo_Fence_Alarm.toString());
List<Alarm> alarms = als.findAlarms(alarm);

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>					

<title><fmt:message key="realtime.geo.fence"/></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" media="all" href="../style.css"/>
<link rel="stylesheet" type="text/css" href="../css/ext-all.css" />
    <script type="text/javascript" src="../js/ext-base.js"></script>
    <script type="text/javascript" src="../js/ext-all.js"></script>
<script type="text/javascript" src="../js/extexample.js"></script>
<script type="text/javascript" src="../js/TableGrid.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript">
var waitingMsg = '<fmt:message key="waiting.msg"/>';
var waitingProgressText = '<fmt:message key="waiting.loading"/>';
function checkDel(){
	return window.confirm("<fmt:message key="control.geofence.delete.confirm"/>")
}
</script>


<script type="text/javascript">
Ext.onReady(function(){

	if(!Ext.isIE6)
		Ext.get("plain-table").setStyle('display','');
    // create the grid
    var grid = new Ext.ux.grid.TableGrid("plain-table", {
        stripeRows: true, // stripe alternate rows
        enableHdMenu:false,
        width:730 
        
    });

    grid.render();

    //Ext.get("plain-table").setStyle('display','');

function createButton(){
	return;
    var buttons = grid.getEl().select('input[type="button"]');
    if(buttons.getCount() == 0){
		setTimeout(createButton, 500);
		return;
    }
    //console.log(buttons, 1000, grid.getEl().dom);
    buttons.each(function(item,c, index){

        var button = new Ext.Button({renderTo:item.parent(),type:'button', 
			text:item.getAttribute('value'),split: true,enableToggle:false});
		button.on('click',function(){
			try{ eval(item.getAttribute('onclick')); }catch(e){}
			});
        item.remove();
    });
}



createButton();

});

</script>
<style type="text/css">


.x-grid3-cell-inner  {
text-align:left;
white-space:nowrap;
}

.x-btn{
float: left;
padding-left:3px;
}


</style>

</head><body bgcolor="#ffffff">
<div style="text-align:left;padding-top: 5px;padding-left: 8px;"><a href="./sysgeofence_edit.jsp?action=geofenceAdd&trackerId=<%=trackerId %>"><fmt:message key="control.geofence.add.new"/></a></div>

<table style="display:none" id="plain-table"  cellspacing="0" width="100%">

	<thead>
	<tr>
		<th width="150"><fmt:message key="tracker.name"/></th>
		<th width="180"><fmt:message key="control.geofence.condition"/></th>
		<th width="80"><fmt:message key="control.geofence.state"/></th>
		<th width="150"><fmt:message key="control.geofence.view"/></th>
		<th width="150"><fmt:message key="control.geofence.operation"/></th>
	</tr>
	</thead>
	<%for(int i = 0; i < alarms.size(); i++){ %>
	<tr>
		<td><%=alarms.get(i).getName()%></td>
		<td><%if(alarms.get(i).getCondition().equals("0")){%><fmt:message key="control.geofence.leave.range"/>
		<%}else if(alarms.get(i).getCondition().equals("1")){ %>
		<fmt:message key="control.geofence.enter.range"/>
		<%} %>
		</td>
		<td><%if(alarms.get(i).getState().equals("0")){%>
		<fmt:message key="control.geofence.state.disable"/>
		<%}else if(alarms.get(i).getState().equals("1")){ %>
		<fmt:message key="control.geofence.state.enable"/>
		<%} %>
		</td>
		<td><a href="#noaction" onclick="parent.locateInMap('<%=alarms.get(i).getData()%>');"><fmt:message key="control.geofence.locate.in.map"/></a></td>
		
		<td><a href="./sysgeofence_edit.jsp?alarmId=<%=alarms.get(i).getAlarmId()%>&action=geofenceEdit&trackerId=<%=tracker.getTrackerid()%>"><fmt:message key="manage.modify"/></a>
		 <a onclick="return checkDel();" href="./sysgeofence.jsp?alarmId=<%=alarms.get(i).getAlarmId()%>&action=del&trackerId=<%=tracker.getTrackerid()%>"><fmt:message key="manage.delete"/></a></td>
	</tr>
	<%} %>
</table>

</body></html>
<%
com.brother.database.DataBase.closeThreadConnection();
%>